/**
 * 加密解密
 * @type {exports}
 */
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
module.exports = {
  md5: function (data) {
    if (data !== undefined) {
      return crypto.createHash("md5").update(new Buffer(data).toString("binary")).digest("hex");
    }
  },
  aes: function (data, decrypt) {
    var key = "d8*#@3d+_(+|d;'f", cipher;
    if (!data) return data;
    if (!!decrypt) {// decrypt
      cipher = crypto.createDecipher('aes-128-ecb', key);
      return cipher.update(data, 'hex', 'utf8') + cipher.final('utf8');
    } else {// encrypt
      cipher = crypto.createCipher('aes-128-ecb', key);
      return cipher.update(data, 'utf8', 'hex') + cipher.final('hex');
    }
  }
};
